package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ScopeOne {
    //    singleton 作用域：
    public static void main(String[] args) {
        singletonTest();
        prototypeTest();
    }

    private static void singletonTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
        SingletonOne objA = (SingletonOne) context.getBean("SingletonOne");
        objA.setMessage("I'm object A");
        objA.getMessage();
        SingletonOne objB = (SingletonOne) context.getBean("SingletonOne");
        objB.getMessage();
//        Your Message : I'm object A
//        Your Message : I'm object A
    }

    private static void prototypeTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
        PrototypeOne objA = (PrototypeOne) context.getBean("PrototypeOne");
        objA.setMessage("I'm object A");
        objA.getMessage();
        PrototypeOne objB = (PrototypeOne) context.getBean("PrototypeOne");
        objB.getMessage();
//        Your Message : I'm object A
//        Your Message : null
    }
}
